import {Component, OnInit, ViewChild} from '@angular/core';
import {_HttpClient, ModalHelper} from '@delon/theme';
import {STColumn, STComponent, STData} from '@delon/abc';
import {SFSchema} from '@delon/form';
import {ActModelEditComponent} from "./edit/edit.component";
import {environment} from "@env/environment";
import {ActModelParamComponent} from "./param/param.component";
import {ActModelImageComponent} from "./image/image.component";
import {ActModelVersionComponent} from "./version/version.component";

@Component({
  selector: 'app-act-model',
  templateUrl: './model.component.html',
})
export class ActModelComponent implements OnInit {
  url = `act/modeler/list`;
  searchSchema: SFSchema = {
    properties: {
      类型: {
        type: 'string',
        title: '类型'
      }
    }
  };
  @ViewChild('st', {static: false}) st: STComponent;
  columns: STColumn[] = [
    {title: 'ID', index: 'id'},
    {title: '键值', index: 'key'},
    {title: '名称', index: 'name'},
    {title: '类型', index: 'category'},
    {title: '创建时间', type: 'date', index: 'createTime'},
    {title: '最后更新时间', type: 'date', index: 'lastUpdateTime'},
    {title: '版本', index: 'revision'},
    {
      title: '',
      buttons: [
        {
          text: `删除`,
          type: 'del',
          click: (record) => this.http.delete(`act/modeler/delete?id=${record.id}`).subscribe(res => this.st.reload())
        },
        {
          text: `发布`,
          type: 'none',
          click: (record) => this.http.post(`act/modeler/publish?id=${record.id}`).subscribe(res => this.st.reload()),
        },
   /*     {
          text: `撤销`,
          type: 'none',
          click: (record) => this.http.post(`act/modeler/revokePublish?id=${record.id}`).subscribe(res => this.st.reload()),
          iif: (item: STData) => {
            return item.deploymentId !== null;
          }
        },*/
        {
          text: '流程设计', type: 'link', click: (item: STData) => {
            window.open(`${environment.SERVER_URL}act/modeler/editor?modelId=${item.id}`)
          }
        },
      ]
    }
  ];

  constructor(private http: _HttpClient, private modal: ModalHelper) {
  }

  ngOnInit() {
  }

  add() {
    this.modal
      .static(ActModelEditComponent, {i: {}})
      .subscribe(() => this.st.reload());
  }

}
